import win32gui
import win32con
import pyautogui
import logging

# 设置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - [ 小助手 ] : %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

logger = logging.getLogger(__name__)

# 屏幕截屏
def capture_window_screenshot(handle, filename):
    left, top, right, bottom = win32gui.GetWindowRect(handle)
    width = right - left
    height = bottom - top
    screenshot = pyautogui.screenshot(region=(left, top, width, height))
    screenshot.save(filename)
    logger.info("窗口截图已保存为: %s", filename)

# 窗口前置
def bring_window_to_front(handle):
    win32gui.ShowWindow(handle, win32con.SW_RESTORE)
    win32gui.BringWindowToTop(handle)
    win32gui.SetForegroundWindow(handle)

# 将窗口设置为指定大小
def set_window_size(handle, width, height):
    win32gui.SetWindowPos(handle, win32con.HWND_TOP, 0, 0, width, height, win32con.SWP_NOZORDER)

if __name__ == "__main__":
 im =  pyautogui.screenshot('Test.png')